package salixtest.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Style;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.*;
import com.googlecode.salix.client.Tree;
import com.googlecode.salix.client.TreeConfig;
import com.googlecode.salix.client.TreeItem;

/**
 * SalixTest.
 *
 * @author <a href="mailto:richard.richter@siemens-enterprise.com">Richard "Virgo" Richter</a>
 */
public class SalixTest implements EntryPoint {
	private FlowPanel exampleSelector;
	private SimplePanel targetPanel;

	public void onModuleLoad() {
		DockLayoutPanel main = new DockLayoutPanel(Style.Unit.PX);
		main.setStyleName("main");

		exampleSelector = new FlowPanel();
		exampleSelector.setStyleName("submain");
		targetPanel = new SimplePanel();
		targetPanel.setStyleName("submain");

		main.addNorth(new HTML("<h1>Salix test application</h1>"), 45);
		main.addWest(exampleSelector, 200);
		main.add(targetPanel);

		addExample("Default Tree", new DefaultTree(true));
		addExample("Pacman Tree", new PacmanTree());
		addExample("Default Unsorted", new DefaultTree(false));

		RootLayoutPanel.get().add(main);
	}

	private void addExample(String name, final Widget example) {
		Button button = new Button(name);
		button.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				targetPanel.setWidget(example);
			}
		});
		exampleSelector.add(button);
	}

	public static Tree createTree(TreeConfig treeConfig) {
		Tree tree = new Tree();
		tree.setWidth("200px");
		tree.setConfiguration(treeConfig);
		TreeItem treeItem;
		tree.addItem("Test 1");
		treeItem = tree.addItem("Test 2");
		treeItem = treeItem.addItem("Subtest");
		treeItem.addItem("lvl3.1");
		treeItem.addItem("lvl3.2");
		treeItem.addItem("lvl3.3");

		treeItem = tree.addItem("Test 3");
		treeItem.addItem("Subtest 3");
		return tree;
	}
}
